import { LabelListItem, LogPageParams, logFetchResult } from './model/msLogsModel';
import { logHttp } from '/@/utils/http/axios';
import moment from 'moment';

enum Api {
  GET_LOG_LIST = '/v1/log/queryLog',
}

export const getSaaSLogList = async (params: LogPageParams) => {
  // 获取操作日志列表
  params.startTimePrimal = moment(params.logTime[0].$d.valueOf()).format('YYYY-MM-DDTHH:mm:ss');
  params.endTimePrimal = moment(params.logTime[1].$d.valueOf()).format('YYYY-MM-DDTHH:mm:ss');
  params.logTime = [];

  const list = await logHttp.post<logFetchResult>({
    url: Api.GET_LOG_LIST,
    params,
  });
  const unitList: LabelListItem[] = [];

  for (let i = 0; i < list.length; i++) {
    unitList.push(list[i].labels);
  }
  // 获取列表转化为标准格式
  return unitList;
};
